import java.util.Arrays;

public class MyStack implements IStack {
    //栈的底层为数组
    private int[] array = new int[10];
    private int usedSize = 0;


    @Override
    public int push(int x) {
        if (this.isFull())
            this.array = Arrays.copyOf(array, array.length * 2);

        return array[usedSize++] = x;
    }

    @Override
    public int pop() throws EmptyException {
        if (usedSize == 0)
            throw new EmptyException("栈为空");

        return this.array[--usedSize];
    }

    @Override
    public int peek() throws EmptyException {
        if (usedSize == 0)
            throw new EmptyException("栈为空");

        return this.array[usedSize - 1];
    }

    @Override
    public int size() {
        return this.usedSize;
    }

    @Override
    public boolean empty() {
        return this.usedSize == 0;
    }

    @Override
    public boolean isFull() {
        return this.array.length == this.usedSize;
    }
}
